from typing import Union
from utils import Color
from filters.manager import FilterManager


@FilterManager.register
def color_to_rgb(color: str):
    return Color(color).to_rgb_string()


@FilterManager.register
def color_to_hsl(color: str):
    return Color(color).to_hsl_string()


@FilterManager.register
def color_to_hex(color: str):
    return Color(color).to_hex_string()


@FilterManager.register
def color_extract(channel_name: str, color: str):
    return Color(color).extract(channel_name)


@FilterManager.register
def color_brightness(color: str):
    return Color(color).brightness


# TODO: 实现对应的算法

@FilterManager.register
def color_modify(channel_name: str, modify_volume: Union[int, float], color: str):
    return Color(color).modify(channel_name, modify_volume)


@FilterManager.register
def color_lighten(volume: int, color: str):
    return Color(color).modify("lightness", volume)


@FilterManager.register
def color_darken(volume: int, color: str):
    return Color(color).modify("lightness", -volume)


@FilterManager.register
def color_saturate(volume: int, color: str):
    return Color(color).modify("saturation", volume)


@FilterManager.register
def color_desaturate(volume: int, color: str):
    return Color(color).modify("saturation", volume)


@FilterManager.register
def color_mix(blend_color: str, blend_tense: str, color: str):
    blend_color = Color(blend_color)
    color = Color(color)
    return color.blend(blend_color, blend_tense)


@FilterManager.register
def color_contrast(other_color: str, color: str):
    return Color(color).contrast(Color(other_color))


@FilterManager.register
def color_difference(other_color: str, color: str):
    return Color(color) - Color(other_color)


@FilterManager.register
def brightness_difference(other_color: str, color: str):
    return Color(color).brightness - Color(other_color).brightness